<?php

namespace app\index\controller;

use app\common\model\MenuModel;
use app\common\model\UserModel;
use app\common\model\Users;
use think\Controller;
use think\db\Where;
use think\facade\Config;
use think\Request;
use app\common\model\Citys;
class City extends Controller
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        return view();
    }
    
    public function data_list(Request $request){
        $model = MenuModel::where('parent_id','=','0');

        if($request->param('id')){
            $model = MenuModel::where('parent_id','=',$request->param('id'));
        }

        $data = $model->select();

        return json($data);
    }

    public function tree(Request $request){
        if(!$request->isAjax()){
            return view();
        }else{
            $model = MenuModel::where('1','=','1');
            if($request->param('searchText')){
                $search = $request->param('searchText');
                $data['searchText'] = $search;
                $model ->where('name|full_name','like',"%$search%");
            }
            $data['rows'] = $model->select();
            foreach ($data['rows'] as $key=>$val){
                $data['rows'][$key]['pname'] = $data['rows'][$key]->pCity['name'];
            }
            //所需字典
            $data['dicts']['has_child'] = Config::get('dicts.has_child');
            return json($data);
        }
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        //
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
    }
}
